<template>
  <BasicDrawer
    v-bind="$attrs"
    @register="registerDrawer"
    :title="getTitle"
    width="1200"
    :showFooter="showFooter"
    destroyOnClose
  >
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item label="类型">
              <j-dict-select-tag placeholder="请选择类型" v-model:value="queryParam.preType" dictCode="caishui_pre_type"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="创建时间">
              <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.createTime_begin" class="query-group-cust" />
              <span class="query-group-split-cust">~</span>
              <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.createTime_end" class="query-group-cust" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button :loading="exportIconLoading" type="primary" preIcon="ant-design:export-outlined" @click="handleExportXls">导出</a-button>
      </template>
      <!--类型插槽-->
      <template #preTypeSlot="{record}">
        <a-badge v-if="record.preType==1" color="red" :text="record.preType_dictText" />
        <a-badge v-if="record.preType==2" color="green" :text="record.preType_dictText" />
        <a-badge v-if="record.preType==3" color="cyan" :text="record.preType_dictText" />
        <a-badge v-if="record.preType==4" color="blue" :text="record.preType_dictText" />
      </template>
      <!--状态插槽-->
      <template #preStatusSlot="{record}">
        <a-tag v-if="record.preStatus==0" color="red">作废</a-tag>
        <a-tag v-if="record.preStatus==1" color="green">正常</a-tag>
      </template>
    </BasicTable>
  </BasicDrawer>
</template>
<script lang="ts" setup>
import {ref, useAttrs, reactive} from "vue";
import {BasicDrawer, useDrawerInner} from "/@/components/Drawer";
import {BasicTable} from "/@/components/Table";
import {useListPage} from "/@/hooks/system/useListPage";
import {itemColumns} from "../CaishuiPreItems.data";
import { itemList, getExportUrl } from "../CaishuiPreItems.api";
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';

// 声明Emits
  const emit = defineEmits(['success', 'register']);
  const attrs = useAttrs();
  const showFooter = ref(false);
  //获取标题
  const getTitle = ref("消费明细");
  const queryParam = ref<any>({});
  const recordData = ref<any>({});
  const exportIconLoading = ref<boolean>(false);

  //抽屉赋值
  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
    setDrawerProps({ confirmLoading: false, showFooter: showFooter.value });
    recordData.value = data.record;
    queryParam.tenantId = recordData.value.tenantId;
  });
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '',
      api: itemList,
      columns: itemColumns,
      canResize:false,
      useSearchForm: false,
      striped: true,
      showIndexColumn: true,
      showActionColumn: false,
      beforeFetch: (params) => {
        params.tenantId = recordData.value.tenantId;
        return Object.assign(params, queryParam.value);
      },
    },
    exportConfig: {
      name: "预充值消费列表",
      url: getExportUrl,
      params: queryParam.value,
      success: exportXlsSuccess
    },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 6 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 导出
   */
  function handleExportXls() {
    exportIconLoading.value = true;
    queryParam.value.tenantId = recordData.value.tenantId;
    onExportXls();
  }

  /**
   * 导出成功回调
   */
  function exportXlsSuccess(data) {
    exportIconLoading.value = false;
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

</script>
<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    margin-bottom: -10px;
    .table-page-search-submitButtons {
      display: block;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
